<template>
<div id="login-all">
    <div class="login_box">
      <div class="avatar_box">
      </div>
      <!--添加表单-->
      <el-form
        ref="loginFormRef"
        :model="loginForm"
        :rules="loginRules"
        class="login_form"
        label-width="0px"
      >
        <el-form-item prop="username">
          <el-input
            v-model="loginForm.username"
            prefix-icon="el-icon-user"
          ></el-input>
        </el-form-item>
        <el-form-item prop="password">
          <el-input
            v-model="loginForm.password"
            prefix-icon="el-icon-lock"
            type="password"
          ></el-input>
        </el-form-item>
        <el-form-item class="btns">
          <el-button @click="login" type="primary">登录</el-button>
          <el-button @click="resetLoginForm" type="info">重置</el-button>
        </el-form-item>
      </el-form>
    </div>
  </div>

  
</template>

<script>
export default {
  data() {
    return {
      loginForm: {
        username: "",
        password: "",
      },
      loginRules: {
        username: [
          {
            required: true,
            message: "请输入用户名",
            trigger: "blur",
          },
          {
            min: 5,
            max: 12,
            message: "长度在 5 到 12 个字符",
            trigger: "blur",
          },
        ],
        password: [
          {
            required: true,
            message: "请输入密码",
            trigger: "blur",
          },
          {
            min: 5,
            max: 12,
            message: "密码为 5~12 位",
            trigger: "blur",
          },
        ],
      },
    };
  },
  methods: {
    resetLoginForm() {
      this.$refs.loginFormRef.resetFields();
    },
    login() {
      this.$refs.loginFormRef.validate(async (valid) => {
        if (!valid) return;
        const { data: res } = await this.$http.post(
          "system/apis/login",
          this.loginForm
        );
        if (res.code == 30000) {
          this.$message.error("没有此用户");
          return;
        }
        if (res.code == 30001) {
          this.$message.error("密码错误");
          return;
        }
        if (res.code == 20000) {
          this.$message.success("登录成功");
          window.sessionStorage.setItem("username", res.data.user.StaffName);
          window.sessionStorage.setItem("level", res.data.user.StaffLevel);
          window.sessionStorage.setItem("remarks", res.data.user.StaffRemarks);
          this.$router.push({ path: "/home" });
          return;
        }
        this.$message.error("后台错误");
      });
    },
  },
};
</script>

<style lang="less" scoped>

#login-all {
  position: fixed;
  height: 100%;
  width: 100%;
  top:0;
  left:0;
  background-image: linear-gradient(
    45deg,
    rgb(255, 0, 0),
    rgb(255, 72, 0),
    rgb(255, 251, 0),
    rgb(43, 255, 0),
    rgb(0, 255, 221),
    rgb(0, 81, 255),
    rgb(204, 0, 255),
    
  );
  background-size: 400%;
  animation: animation 10s infinite;
}
@keyframes animation {
  0% {
    background-position: 0% 50%;
  }
  50% {
    background-position: 100% 50%;
  }
  100% {
    background-position: 0% 50%;
  }
}

// 登录框
.login_box {
  width: 450px;
  height: 300px;
  border-radius: 3px; // 圆角
  position: absolute; // 绝对定位
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%); // 根据自己位置 以自己为长度位移



  .btns {
    display: flex; // 弹性布局
    justify-content: center; // 尾部对齐
  }

  .login_form {
    position: absolute;
    bottom: 0%;
    width: 100%;
    padding: 0 10px;
    box-sizing: border-box; // 设置边框
  }
}
</style>